﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;
using Microsoft.SharePoint;

namespace SDS.SharePoint.CustomConditions
{
    public class ApprovalStatus
    {
        public static bool IfApprovalStatus(WorkflowContext context, string listId, int itemId, string StatusTestValue)
        {
            bool outval = false;
            try
            {
                var tWeb = context.Web;
                var tItem = tWeb.GetListItem(context.CurrentItemUrl);
                SPModerationStatusType TestValueModerationStatusType = (SPModerationStatusType) Enum.Parse(typeof (SPModerationStatusType), StatusTestValue, true);
                outval = tItem.ModerationInformation.Status == TestValueModerationStatusType;
            }
            catch (Exception ex)
            {
                //ISharePointService sharePointService = (ISharePointService)context.GetService(typeof(ISharePointService));
                //if (sharePointService != null)
                //{
                //    sharePointService.LogToHistoryList(context.WorkflowInstanceId, SPWorkflowHistoryEventType.WorkflowError, context.InitiatorUser.ID, TimeSpan.MinValue, String.Empty, ex.Message, String.Empty);
                //}
            }
            return outval;
        }
    }
}
